package com.fengye.user.controller;

import com.fengye.user.dto.UserDTO;
import com.fengye.user.util.ServletContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class TestController {

    @GetMapping("/test")
    public String test(UserDTO userDTO) {
        log.info("userDTO:{}", userDTO);
        HttpServletRequest httpServletRequest = ServletContextHolder.get();
        httpServletRequest.getHeaderNames().asIterator().forEachRemaining(header -> log.info("header:{} - {}", header, httpServletRequest.getHeader(header)));
        return "hello world";
    }

    @GetMapping("/user")
    public String user(@RequestParam String tenantCode) {
        log.info("tenantCode:{}", tenantCode);
        HttpServletRequest httpServletRequest = ServletContextHolder.get();
        httpServletRequest.getHeaderNames().asIterator().forEachRemaining(header -> log.info("header:{} - {}", header, httpServletRequest.getHeader(header)));
        return "hello world";
    }
}
